package com.vains.config.bean;

import com.vains.config.feign.FeignBasicAuthRequestInterceptor;
import feign.RequestInterceptor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.oauth2.provider.expression.OAuth2WebSecurityExpressionHandler;

@Order(-1)
@Configuration
public class SecurityBeanConfig {

    /**
     * .anyRequest().access() 使用该方法要配置该bean
     * @param applicationContext 当前上下文
     * @return OAuth2WebSecurityExpressionHandler
     */
    @Bean
    public OAuth2WebSecurityExpressionHandler oAuth2WebSecurityExpressionHandler(ApplicationContext applicationContext) {
        OAuth2WebSecurityExpressionHandler expressionHandler = new OAuth2WebSecurityExpressionHandler();
        expressionHandler.setApplicationContext(applicationContext);
        return expressionHandler;
    }

    /**
     * feign请求拦截器
     *
     * @return FeignBasicAuthRequestInterceptor
     */
    @Bean
    public RequestInterceptor requestInterceptor(){
        return new FeignBasicAuthRequestInterceptor();
    }

}
